package com.ymatou.iapi.idcardmng.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.idcardmng.parameter.DeleteIdCardInfoBean;
import com.ymatou.iapi.idcardmng.service.DeleteIdCardInfoCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P3;
import com.ymttest.database.model.YmtIdCardInfo;
import com.ymttest.database.sqlwapper.YmtIdCardInfoWapper;
import com.ymttest.utils.EnvSetup;
/**
*逻辑删除身份证信息（本地库）接口
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_DeleteIdCardInfo {
	private static DeleteIdCardInfoBean deleteidcardinfoBean;
	private static DeleteIdCardInfoCall deleteidcardinfoCall;
	String key = "1234567890123456";
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("逻辑删除身份证信息（本地库）接口");
	}

	@Before
	public void caseUp() {
		deleteidcardinfoBean = new DeleteIdCardInfoBean();
		deleteidcardinfoCall = new DeleteIdCardInfoCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(deleteidcardinfoCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_DeleteIdCardInfo_001() {
		Logger.start(true, "根据用户id,姓名删除在本地数据库删除身份证信息成功");
		try {

			long buyerId = Long.valueOf(EnvSetup.getData("SellerId2"));

			YmtIdCardInfoWapper ymtIdCard = new YmtIdCardInfoWapper();;

			YmtIdCardInfo ymtIdCardInfo = ymtIdCard.selectByUserId(buyerId, 1, true, 0).get(0);;

			String name = ymtIdCardInfo.getName();

			String cardNumber = ymtIdCardInfo.getIDCard();

			deleteidcardinfoBean.setBuyerId(buyerId);
			deleteidcardinfoBean.setName(name);

			deleteidcardinfoCall.setData(deleteidcardinfoBean);
			deleteidcardinfoCall.callService();

			Logger.verifyEquals("200", deleteidcardinfoCall.getString("Code"),
					"验证Code");

			ymtIdCardInfo = ymtIdCard.selectByNameAndId(name, cardNumber);

			Logger.verifyEquals(1, ymtIdCardInfo.getIsDelete(), "校验buyerid");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_DeleteIdCardInfo_002() {
		Logger.start(true, "用户id为null");
		try {

			//deleteidcardinfoBean.setBuyerId(buyerId);
			deleteidcardinfoBean.setName("name");

			deleteidcardinfoCall.setData(deleteidcardinfoBean);
			deleteidcardinfoCall.callService();

			Logger.verifyEquals("400", deleteidcardinfoCall.getString("Code"),
					"验证Code");

			Logger.verifyEquals("100", deleteidcardinfoCall.getString("BCode"),
					"验证BCode");
			Logger.verifyEquals("buyerId:买家Id不能为空",
					deleteidcardinfoCall.getString("Msg"), "验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_DeleteIdCardInfo_003() {
		Logger.start(true, "name为null");
		try {

			deleteidcardinfoBean.setBuyerId(288484L);
			//deleteidcardinfoBean.setName("name");

			deleteidcardinfoCall.setData(deleteidcardinfoBean);
			deleteidcardinfoCall.callService();

			Logger.verifyEquals("400", deleteidcardinfoCall.getString("Code"),
					"验证Code");

			Logger.verifyEquals("100", deleteidcardinfoCall.getString("BCode"),
					"验证BCode");
			Logger.verifyEquals("name:名称未提供",
					deleteidcardinfoCall.getString("Msg"), "验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_DeleteIdCardInfo_004() {
		Logger.start(true, "用户id不存在");
		try {

			deleteidcardinfoBean.setBuyerId(288482L);
			deleteidcardinfoBean.setName("name");

			deleteidcardinfoCall.setData(deleteidcardinfoBean);
			deleteidcardinfoCall.callService();

			Logger.verifyEquals("500", deleteidcardinfoCall.getString("Code"),
					"验证Code");

			Logger.verifyEquals("199", deleteidcardinfoCall.getString("BCode"),
					"验证BCode");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_DeleteIdCardInfo_005() {
		Logger.start(true, "用户id跟name不匹配");
		try {

			deleteidcardinfoBean.setBuyerId(288484L);
			deleteidcardinfoBean.setName("张三");

			deleteidcardinfoCall.setData(deleteidcardinfoBean);
			deleteidcardinfoCall.callService();

			Logger.verifyEquals("500", deleteidcardinfoCall.getString("Code"),
					"验证Code");

			Logger.verifyEquals("199", deleteidcardinfoCall.getString("BCode"),
					"验证BCode");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}